

//工具类使用abstract定义时,写代码时不会提示创建实例选项
import 'package:flutter/material.dart';
import 'package:reabampos/src/reabam/utils/rb_color.dart';
import 'package:xsdk_flutter/xsdk/xsdk_flutter_package.dart';

abstract class RBWidgets{

  //搜索条
  static Widget getSearchBarWidget({
    required XFunctionResultCallback<String>? searchResultCallback,
    required XFunctionWidgetOnClick<String?>? onTapSearch,
    String? initSearchValue, //初始值
    bool autofocus=false,
    String? hintText = '请输入搜索内容',
    int rightCustomWidgetType = 0, //自定义右侧图标, 0:不显示, 1:高级筛选图标, 2:商品分类图标, 3:扫描图标
    List<Widget>? rightCustomWidgets,
    bool isShowLeftBackIcon = false,
    GestureTapCallback? onTapRightCustomIcon,
    Color outSideBackgroundColor = Colors.white,
    Color? searchBarBackgroundColor,
    Color iconColor = XColorUtils.colorCCCCCC,
    Color textColor = XColorUtils.color333333,
    Color hintTextColor = XColorUtils.colorCCCCCC,
    EdgeInsets? margin,
  }) {
    //自定义右侧图标
    List<Widget> outsideRightCustomWidgets = [];
    if (rightCustomWidgetType == 1) {
      //高级筛选图标
      outsideRightCustomWidgets.add(XWidgetUtils.getWidgetGestureDetector(
        child: XWidgetUtils.getLayoutPadding(
            padding: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
            child: XImageUtils.getImageWidgetWithAsset(
              'shaixuan_5.png',
              width: 24,
              height: 24,
              color: iconColor,
            )),
        onTap: onTapRightCustomIcon,
      ));
    } else if (rightCustomWidgetType == 2) {
      //商品分类图标
      outsideRightCustomWidgets.add(XWidgetUtils.getWidgetGestureDetector(
        child: XWidgetUtils.getLayoutPadding(
            padding: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
            child: XImageUtils.getImageWidgetWithAsset(
              'fenlei_black.png',
              width: 24,
              height: 24,
              color: iconColor,
            )),
        onTap: onTapRightCustomIcon,
      ));
    } else if (rightCustomWidgetType == 3) {
      //扫描图标
      outsideRightCustomWidgets.add(XWidgetUtils.getWidgetGestureDetector(
        child: XWidgetUtils.getLayoutPadding(
            padding: XWidgetUtils.getEdgeInsets(0, 0, 10, 0),
            child: XImageUtils.getImageWidgetWithAsset(
              'saoyisao_er.png',
              width: 24,
              height: 24,
              color: iconColor,
            )),
        onTap: onTapRightCustomIcon,
      ));
    } else if (rightCustomWidgets != null && rightCustomWidgets.isNotEmpty) {
      // 自定义图标
      outsideRightCustomWidgets.addAll(rightCustomWidgets);
    }

    return XStatefulWidget(() => XComponentSearchBarState(
      initSearchValue: initSearchValue,
      searchResultCallback: searchResultCallback,
      isShowLeftBackIcon: isShowLeftBackIcon,
      hintText: hintText,
      outsideRightCustomWidgets: outsideRightCustomWidgets,
      outSideBackgroundColor: outSideBackgroundColor,
      searchBarBackgroundColor: searchBarBackgroundColor,
      iconColor: iconColor,
      textColor: textColor,
      hintTextColor: hintTextColor,
      onTapSearch: onTapSearch,
      margin: margin,
      autofocus:autofocus,
    ));
  }




}
